package cn.zhp.controller;


import cn.zhp.entity. Qualification;
import cn.zhp.entity.QualificationCondition;
import cn.zhp.entity.Result;
import cn.zhp.service. QualificationService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@RestController
@RequestMapping("manager/qualification")
public class QualificationController {

    @Autowired
     QualificationService service;

    @RequestMapping("index")
    public ModelAndView index(){
        return new ModelAndView("/qualification/index");
    }

    @RequestMapping("toUpdate")
    public ModelAndView toUpdate(){
        return new ModelAndView("/qualification/update");
    }



    @RequestMapping("selectPage/{pageNum}/{size}")
    public Result selectPage(@PathVariable("pageNum")int pageNum, @PathVariable("size")int size, /*@RequestBody*/ QualificationCondition condition){
        PageInfo pageInfo = service.selectPage(pageNum, size,condition);
        return new Result(true,null,pageInfo);
    }

    @RequestMapping("doUpdate")
    public Result doUpdate(@RequestBody  Qualification qualification){
        qualification.setUpdateDate(new Date());
        service.updateByPrimaryKeySelective(qualification);
        return new Result(true,"更新成功",null);
    }


    @RequestMapping("insert")
    public Result insert(@RequestBody  Qualification qualification){
        qualification.setCreateDate(new Date());
        qualification.setUpdateDate(new Date());
        qualification.setDelFlag("0");
        service.insertSelective(qualification);
        return new Result(true,"新增成功",null);
    }

    @RequestMapping("delete/{id}")
    public Result delete(@PathVariable("id") long id){
         Qualification appVersion = new  Qualification();
        appVersion.setId(id);
        appVersion.setUpdateDate(new Date());
        appVersion.setDelFlag("1");
        service.updateByPrimaryKeySelective(appVersion);
        return new Result(true,"删除成功",null);
    }
}
